package login

import (
	"context"
	"net/http"

	"ruoyi_zero/internal/svc"
	"ruoyi_zero/internal/types"
	"ruoyi_zero/utils"
	"strings"

	"github.com/zeromicro/go-zero/core/logx"
)

type CaptchaImageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCaptchaImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CaptchaImageLogic {
	return &CaptchaImageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CaptchaImageLogic) CaptchaImage() (resp *types.CaptImgResponse, err error) {
	// todo: add your logic here and delete this line

	resp = new(types.CaptImgResponse)
	id, b64s, _, err := utils.CreateImageCaptcha()
	if err != nil {
		logx.Info(err.Error())
	}
	resp.Uuid = id
	resp.Img = strings.ReplaceAll(b64s, "data:image/png;base64,", "")
	resp.Msg = "操作成功"
	resp.Code = http.StatusOK
	resp.CaptchaEnabled = true
	return
}
